// 获取全局应用程序实例对象
const app = getApp();
const {get,post} = app.utils.request;
const {order_command} = app.utils.config;

// 创建页面实例对象
Page({
	// 页面的初始数据
	data: {
		title: '评价',
		evaluate: {
			order_id: '',
			star_grade: '',
			comment: ''
		}
	},

	// 生命周期函数--监听页面加载
	onLoad(options) {
		console.log(options);
		const {id} = options;
		this.setData({
			'evaluate.order_id': id
		});
	},

	// 页面分享设置
	onShareAppMessage() {
		return {
			title: 'share title',
			path: 'pages/evaluate/evaluate',
		};
	},
	rateCallback(res){
		this.setData({
			'evaluate.star_grade': res.detail.starNum
		});
	},
	getComment(evt){
		setTimeout(()=>{
			var comment = evt.detail.value;
			this.setData({
				'evaluate.comment': comment
			});
		},300);
	},
	submit(){
		var data = this.data.evaluate;
		post({path: `${order_command}`}, data)
		.then((res) => {
			console.log(res.ret == 0);
			if (res.ret == 0) {
				wx.navigateBack({
					delta: 1
				});
			}
		});
	}
});
